﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ProjectRoughWork
{
    class ActorManagementListener : EventListener
    {
        /// <summary>
        /// 1-Parameter Default consructor, Initializes the gameply screen that'll handle actor events
        /// </summary>
        /// <param name="screen"></param>

        public ActorManagementListener(GameplayScreen screen)
        {
            gameScreen = screen;
        }

        public override void VHandleEvent(IEventData eventData)
        {
            if (eventData.VGetEventType().Equals("AddActor"))
            {
                //Typecast the event, retrieve the actor to add and call the appropriate function in the GameplayScreen

                EventAddActor addEvt = (EventAddActor)eventData;
                IActor newActor = addEvt.NewActor;

                gameScreen.AddActor(newActor);
            }
            else if (eventData.VGetEventType().Equals("RemoveActor"))
            {
                //Typecast the event, retrieve the ID of the actor to be removed and call the appropriate function in the GameplayScreen

                EventRemoveActor rmEvt = (EventRemoveActor)eventData;
                int actorID = rmEvt.ActorID;

                gameScreen.RemoveActor(actorID);
            }
            else if (eventData.VGetEventType().Equals("MoveActor"))
            {
                //Typecast the event, retrieve the ID of the actor to be moved and the new position and call the appropritate function in 
                //the GameplayScreen class

                EventMoveActor mvEvt = (EventMoveActor)eventData;
                int actorID = mvEvt.ActorID;
                Vector3 newPosition = mvEvt.NewPosition;

                gameScreen.MoveActor(actorID, newPosition);
            }
            else if (eventData.VGetEventType().Equals("AttachProcess"))
            {
                //Typecast the event, retrieve the process to be attached and call the appropriate function in the GameplayScreen

                EventAttachProcess attachEvt = (EventAttachProcess)eventData;
                CProcess newProcess = attachEvt.NewProcess;

                gameScreen.AttachProcess(newProcess);
            }
            else if (eventData.VGetEventType().Equals("DealDamage"))
            {
                //Typecast the event, retrieve the actor to get hurt, the damage take and the radius of the damage and 
                //call the appropriate function in the GameplayScreen

                EventDealDamage damageEvt = (EventDealDamage)eventData;
                int actorID = damageEvt.ActorID;
                int damage = damageEvt.Damage;
                int radius = damageEvt.Radius;

                gameScreen.DealDamage(actorID, damage, radius);
            }
            else if (eventData.VGetEventType().Equals("GiveXP"))
            {
                //Typecast the event, retrieve the actor to give XP and the amount of XP to give and 
                //call the appropriate function in the GameplayScreen

                EventGiveXP xpEvt = (EventGiveXP)eventData;
                int actorID = xpEvt.ActorID;
                int xp = xpEvt.XP;

                gameScreen.GiveXP(actorID, xp);
            }
            else if (eventData.VGetEventType().Equals("CoverCheck"))
            {
                //Typecast the event, retrieve the actor to check and call the appropriate function in the GameplayScreen

                EventCoverCheck checkEvt = (EventCoverCheck)eventData;
                SquadActor actor = checkEvt.Actor;

                gameScreen.CoverCheck(actor);
            }
            else if (eventData.VGetEventType().Equals("Explode"))
            {
                EventExplode expEvt = (EventExplode)eventData;
                Vector3 position = expEvt.Position;
                int damage = expEvt.Damage;
                int radius = expEvt.Radius;

                gameScreen.Explode(position, damage, radius);
            }
            
            base.VHandleEvent(eventData);
        }

        //Data Members

        GameplayScreen gameScreen;
    }
}
